#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1000;
const int M = 1e9 + 7;

int t;
string s;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while (t--) {
        cin >> s;
        map<int, int> m;
        for (auto ch : s) {
            m[ch - 'A']++;
        }
        puts(m[1] == m[0] + m[2] ? "YES" : "NO");
    }
    return 0;
}